
/* _____________________________________________________________________________

* 	Paper: Perspective-Taking Through Partisan Eyes
* 	Replication File - Read Me
* 	Date: 2022
* 	Authors: Donald Casler and Dylan Groves, dylanwgroves@gmail.com
________________________________________________________________________________*/


/* Introduction ________________________________________________________________*/

	clear all
	set more off

/* Set Global ___________________________________________________________________*/

	gl stata "X:\Dropbox\Paper - PTinIR\09 Code\07_Replication\"

/* Import Data _________________________________________________________________*/

	use "${stata}\ptinir_data_wave1_raw.dta", clear


/* Pre-Treatment Covariates ____________________________________________________*/

	encode q1, gen(consent2)
	gen consent = consent2
	lab def consent 0 "No Consent" 1 "Consent"
	lab val consent consent
	drop consent2
	lab var consent "Consent"

	* Ideology (Short)
	gen c_pid = 3 if q34 == "Democrat"
	replace c_pid = 2 if q34 == "Independent"
	replace c_pid = 1 if q34 == "Republican"
	replace c_pid = .o if q34 == "Other"
	replace c_pid = .d if q34 == "Don't Know"

	lab def c_pid 3 "Democrat" 2 "Independent" 1 "Republican" .o "Other" .d "Don't Know"
	lab val c_pid c_pid
	lab var c_pid "Party ID (short)"

	* Ideology (Long)
	gen c_pid_long = 5 if q35 == "Strong Democrat"
	replace c_pid_long = 4 if q35 == "Democrat"
	replace c_pid_long = 4 if q35 == "Lean Democrat"
	replace c_pid_long = 3 if q34 == "Independent"
	replace c_pid_long = 2 if q38 == "Lean Republican"
	replace c_pid_long = 2 if q38 == "Republican"
	replace c_pid_long = 1 if q38 == "Strong Republican"
	replace c_pid_long = .o if q34 == "Other"
	replace c_pid_long = .d if q34 == "Don't Know"


	lab def c_pid_long 5 "Strong Democrat" 4 "Democrat" 3 "Independent" 2 "Republican" 1 "Strong Republican" .o "Other" .d "Don't Know"
	lab val c_pid_long c_pid_long
	lab var c_pid_long "Party ID (Long)"

	* Democrat
	gen c_dem = 1 if c_pid == 3
	replace c_dem = 0 if c_pid != 3

	lab def c_dem 1 "Democrat" 0 "Non-Democrat"

	* Gender
	encode q2, gen(gender)
	gen c_male = .
	replace c_male = 0 if gender == 1
	replace c_male = 1 if gender == 2

	lab def c_male 1 "Male" 0 "Female"

	gen c_age = q3
	lab var c_age "Age"

	encode q4, gen(c_race)


	gen c_white = .
	replace c_white = 1 if c_race == 7
	replace c_white = 0 if c_race != 7

	lab def c_white 1 "White" 0 "Non-White"
	lab val c_white c_white
	lab var c_white "White"

	gen c_black = .
	replace c_black = 1 if c_race == 3
	replace c_black = 0 if c_race != 7


	gen c_latino = .
	replace c_latino = 1 if q4 == "Hispanic or Latino American"
	replace c_latino = 0 if q4 != "Hispanic or Latino American"

	* Education
	gen c_edu = 1 if q5 == "Less than a complete high school education"
	replace c_edu = 2 if q5 == "Complete high school education"
	replace c_edu = 3 if q5 == "Some college-level education, without degree"
	replace c_edu = 4 if q5 == "College-level education, with degree"
	replace c_edu = 5 if q5 == "Some post-graduate education, without degree"
	replace c_edu = 6 if q5 == "Post-graduate education, with degree"

	lab def c_edu 1 "Less than high school" 2 "High School" 3 "Some college" 4 "College" 5 "Some post-grad" 6 "Post-grad"
	lab val c_edu c_edu
	lab var c_edu "education"

	* Income
	gen c_income = 1 if q6 == "Less than $50,000"
	replace c_income = 2 if q6 == "$50,000-$100,000"
	replace c_income = 3 if q6 == "$100,000 or more"

	lab def income 1 "50k" 2 "50-100k" 3 "100k+"
	lab val c_income income	
	lab var c_income "Income"


	* Interventionist
	gen c_interventionist = 0 if q10 == "Strongly disagree"
	replace c_interventionist = 1 if q10 == "Somewhat disagree"
	replace c_interventionist = 2 if q10 == "Somewhat agree"
	replace c_interventionist = 3 if q10 == "Strongly agree"

	lab def c_interventionist 0 "Strongly disagree" 1 "Somewhat disagree" 2 "Somewhat agree" 3 "Strongly agree"
	lab val c_interventionist c_interventionist
	lab var c_interventionist "USA needs to play an active role in solving problem saround the world"

	* Trusting
	gen c_trust = 1 if q11 == "The United States can trust other nations"
	replace c_trust = 0 if q11 == "The United States can't be too careful"

	lab def c_trust 0 "Can't be too careful" 1 "Can trust"
	lab val c_trust c_trust
	lab var c_trust "Can USA trust other nations?"

	* Perspective Taking Skills
	forval i = 1/5 {

	gen c_pt_`i' = 0 if q18_`i' == "Not well at all"
	replace c_pt_`i' = 1 if q18_`i' == "Somewhat well"
	replace c_pt_`i' = 2 if q18_`i' == "Moderately well"
	replace c_pt_`i' = 3 if q18_`i' == "Extremely well"

	lab def c_pt_`i' 0 "Not well" 1 "Somewhat well" 2 "Moderate well" 3 "Extremely well"
	lab val c_pt_`i' c_pt_`i'
	}

	rename c_pt_1 c_pt_allsides
	lab var c_pt_allsides "I try to look at everyones side of disagreement"

		rename c_pt_2 c_pt_touched
		lab var c_pt_touched "I am often quite touched by things that I see happen"

		rename c_pt_3 c_pt_tender
		lab var c_pt_tender "I often have tender, concern feelings for people less fortunate"

		rename c_pt_4 c_pt_nopov
		lab var c_pt_nopov "I sometimes find it difficult to see things from other guy's point of view"
		revrs c_pt_nopov

		rename c_pt_5 c_pt_notsorry
		lab var c_pt_notsorry "Sometimes I dont feel very sorry for other people"
		revrs c_pt_nopov

	gen c_pt_index = (c_pt_allsides + c_pt_touched + c_pt_tender + (3-c_pt_nopov) + (3-c_pt_notsorry))/5
	lab var c_pt_index "Sum of PT variables (coded in PT+ direction) / 5"

	gen c_ce_index = (c_pt_allsides + (3-c_pt_nopov))/2
	gen c_ee_index = (c_pt_touched + c_pt_tender + (3-c_pt_notsorry))/3


	*-------------------------------------------------------------------------------
	* Treatment Conditions
	*-------------------------------------------------------------------------------

	** Overall Treatment Condition
	gen treat = 1 if fl_450_do == "FL_269"
	replace treat = 2 if fl_450_do == "FL_372"
	replace treat = 3 if fl_448_do == "FL_383"
	replace treat = 4 if fl_448_do == "FL_274"
	replace treat = 5 if fl_446_do == "FL_394"
	replace treat = 6 if fl_446_do == "FL_279"
	replace treat = 7 if fl_444_do == "FL_405"
	replace treat = 8 if fl_444_do == "FL_329"
	replace treat = 9 if fl_441_do == "FL_416"
	replace treat = 10 if fl_441_do == "FL_282"
	replace treat = 11 if fl_440_do == "FL_289"
	replace treat = 12 if fl_440_do == "FL_429"
	replace treat = 13 if fl_486_do == "FL_487"
	replace treat = 14 if fl_486_do == "FL_498"

	#d ;
	lab def treat 
			1 "(1) Control Nukes (2) India CC" 
			2 "(1) India CC (2) Control Nukes"
			3 "(1) China Nukes (2) India CC"
			4 "(1) India CC (2) China Nukes"
			5 "(1) Control Nukes (2) China CC"
			6 "(1) China CC (2) Control Nukes"
			7 "(1) India Nukes (2) China CC"
			8 "(1) China CC (2) India Nukes"
			9 "(1) China Nukes (3) Control CC"
			10 "(1) Control CC (2) China Nukes"
			11 "(1) India Nukes (2) Control CC"
			12 "(1) Control CC (2) India Nukes" 
			13 "(1) Control Nukes (2) Control CC" 
			14 "(1) Control CC (2) Control Nukes";
	#d cr

	lab val treat treat
	lab var treat "Treatment Condition"


	* Topic by Order
	gen treat_topic_1 = 0 if treat == 2 | treat == 4 | treat == 6 | treat == 8 | treat == 10 | treat == 12 | treat == 14
	replace treat_topic_1 = 1 if treat == 1 | treat == 3 | treat == 5 | treat == 7 | treat == 9 | treat == 11 | treat == 13
	lab def treat_topic 0 "Climate" 1 "Nukes"
	lab val treat_topic_1 treat_topic
	lab var treat_topic_1 "Topic of 1st"

	gen treat_topic_2 = 1 if treat_topic_1 == 0
	replace treat_topic_2 = 0 if treat_topic_1 == 1
	lab val treat_topic_2 treat_topic
	lab var treat_topic_2 "Topic of 2nd"

	* Treatment By Treatment Order
	gen treat_1 = 0 if treat == 1 | treat == 5 | treat == 10 | treat == 12 | treat == 13 | treat == 14
	replace treat_1 = 1 if treat == 2 | treat == 4| treat == 7 | treat == 11
	replace treat_1 = 2 if treat == 3 | treat == 6 | treat == 8 | treat == 9

	gen treat_2 = 0 if treat == 2 | treat == 6 | treat == 9 | treat == 11
	replace treat_2 = 1 if treat == 1 | treat == 3 | treat == 8 | treat == 12
	replace treat_2 = 2 if treat == 4 | treat == 5 | treat == 7 | treat == 10 

	lab def treat_c 0 "Control" 1 "India" 2 "China"
	lab val treat_1 treat_c
	lab val treat_2 treat_c

	* Climate Change Treatment
	gen treat_climate = 0 if treat == 9 | treat == 10 | treat == 11 | treat == 12 | treat == 13 | treat == 14

	replace treat_climate = 1 if treat == 1 | treat == 2 | treat == 3 | treat == 4
	replace treat_climate = 2 if treat == 5 | treat == 6 | treat == 7 | treat == 8

	lab val treat_climate treat_c
	lab var treat_climate "Climate Change Treatment Condition"

	gen treatdum_climate = 1 if treat_climate == 1 | treat_climate == 2
	replace treatdum_climate = 0 if treat_climate == 0
	lab var treatdum_climate "PT Treatment (Climate)"

	* Climate Change Order
	gen order_climate = 1 if treat == 2 | treat == 4 | treat == 6 | treat == 8 | treat == 10 | treat == 12 | treat == 14
	replace order_climate = 2 if treat == 1 | treat == 3 | treat == 5 | treat == 7 | treat == 9 | treat == 11 | treat == 13

	lab def order_c 1 "First" 2 "Second"
	lab val order_climate order_c
	lab var order_climate "Order in which CC appeared"

	* Nukes Treatment
	gen treat_nukes = 0 if treat == 1 | treat == 2 | treat == 5 | treat == 6 | treat == 13 | treat == 14
	replace treat_nukes = 1 if treat == 7 | treat == 8 | treat == 11 | treat == 12
	replace treat_nukes = 2 if treat == 3 | treat == 4 | treat == 9 | treat == 10

	lab val treat_nukes treat_c
	lab var treat_nukes "Nukes Treatment Condition"

	* Nukes Treatment Dummy
	gen treatdum_nukes = 1 if treat_nukes == 1 | treat_nukes == 2
	replace treatdum_nukes = 0 if treat_nukes == 0
	lab var treatdum_nukes "PT Treatment (Nukes)"

	* Nukes Order
	gen order_nukes = 3-order_climate
	lab val order_nukes order_climate
	lab var order_nukes "Order in which nukes appeared"


	*-------------------------------------------------------------------------------
	* Outcomes
	*-------------------------------------------------------------------------------

	** Nuclear

	* Coop
	gen dv_nukecoop = 1 if q62 == "Strongly oppose"
	replace dv_nukecoop = 2 if q62 == "Somewhat oppose"
	replace dv_nukecoop = 3 if q62 == "Neither support nor oppose"
	replace dv_nukecoop = 4 if q62 == "Somewhat support"
	replace dv_nukecoop = 5 if q62 == "Strongly support"

	lab def dv_coop 1 "Strongly oppose" 2 "Somewhat oppose" 3 "Neither" 4 "Somewhat support" 5 "Strongly support"
	lab val dv_nukecoop dv_coop
	lab var dv_nukecoop "[Nukes] Accept Treaty"

	* Condition
	gen dv_nukecondition = 0 if q63 == "The US should not stop developing and producing tactical nuclear weapons" | ///
								q63 == "The US  should stop producing tactical nuclear weapons ONLY IF other countries also stop producing tactical nuclear weapons"

	replace dv_nukecondition = 1 if q63 == "Only if other countries agree to stop developing and producing tactical nuclear weapons" | ///
									q63 == "The US should NOT stop producing tactical nuclear weapons"
					
	replace dv_nukecondition = 2 if q63 == "Regardless of what other countries do" | ///
									q63 == "The US should stop producing tactical nuclear weapons REGARDLESS of what other countries do"
											

	lab def dv_condition 0 "Never" 1 "Conditionally" 2 "Unconditionally"

	lab val dv_nukecondition dv_condition
	lab var dv_nukecondition "The US should stop developing tactical nukes if..."

	* Uncondition
	gen dv_nukeuncondition = 0 if dv_nukecondition == 0 | dv_nukecondition == 1
	replace dv_nukeuncondition = 1 if dv_nukecondition == 2
	lab var dv_nukeuncondition "Unconditional support for nuclear coop"
	lab def dv_uncondition 0 "Not unconditional support" 1 "Unconditional support"
	lab val dv_nukeuncondition dv_uncondition

	* Qualitative
	gen dv_qual_nukes = q58


	** Climate Change

	* Coop
	gen dv_climatecoop = 1 if q19 == "Strongly oppose"
	replace dv_climatecoop = 2 if q19 == "Somewhat oppose"
	replace dv_climatecoop = 3 if q19 == "Neither support nor oppose"
	replace dv_climatecoop = 4 if q19 == "Somewhat support"
	replace dv_climatecoop = 5 if q19 == "Strongly support"

	lab val dv_climatecoop dv_coop
	lab var dv_climatecoop "[Climate] Accept Treaty"

	* Conditional
	gen dv_climatecondition = 0 if q20 == "The US should not tax energy to reduce its emissions" | ///
								   q20 == "The US should not reduce its emissions" | ///
								   q20 == "The US should NOT tax energy to reduce greenhouse gas emissions"
								   
	replace dv_climatecondition = 1 if q20 == "Only if other countries reduce their emissions" | ///
									   q20 == "The US should tax energy to reduce greenhouse gas emissions ONLY IF other countries also tax energy to reduce greenhouse gas emissions"

	replace dv_climatecondition = 2 if q20 == "Regardless of what other countries do" | ///
									   q20 == "The US should tax energy to reduce greenhouse gas emissions REGARDLESS of what other countries do"

	lab val dv_climatecondition dv_condition
	lab var dv_climatecondition "The US should tax energy to reduce its gg emissions if..."


	gen dv_climateuncondition = 0 if dv_climatecondition == 0 | dv_climatecondition == 1
	replace dv_climateuncondition = 1 if dv_climatecondition == 2
	lab var dv_climateuncondition "Unconditional support for climate coop"
	lab val dv_climateuncondition dv_uncondition

	* Qualitative
	gen dv_qual_clim = q21

	*-------------------------------------------------------------------------------
	* Mechanism Check
	*-------------------------------------------------------------------------------

	* Mechanism Check
	gen mech_nukechina = 1 if q51 == "Accept nuclear treaty requirements (stop development and production of tactical nuclear weapons)"
	replace mech_nukechina = 0 if q51 == "Reject nuclear treaty requirements (continue development and production of tactical nuclear weapons)"

	gen mech_nukeindia = 1 if q45 == "Accept nuclear treaty requirements (stop development and production of tactical nuclear weapons)"
	replace mech_nukeindia = 0 if q45 == "Reject nuclear treaty requirements (continue development and production of tactical nuclear weapons)"

	gen mech_climatechina = 1 if q16 == "Accept climate treaty requirements (reduce carbon emissions by taxing energy)"
	replace mech_climatechina = 0 if q16 == "Reject climate treaty requirements (do not reduce carbon emission by taxing energy)"

	gen mech_climateindia = 1 if q15 == "Accept climate treaty requirements (reduce carbon emissions by taxing energy)"
	replace mech_climateindia = 0 if q15 == "Reject climate treaty requirements (do not reduce carbon emission by taxing energy)"

	lab def mechanism 1 "Accept treaty" 0 "Reject treaty"

	foreach var of varlist mech_nukechina mech_nukeindia mech_climatechina mech_climateindia {
	lab val `var' mechanism
	lab var `var' "If you were X country would you sign treaty?"
	}

	* Overall Mech
	egen mech_nuke = rowmean(mech_nukechina mech_nukeindia)
	egen mech_climate = rowmean(mech_climatechina mech_climateindia)
	egen mech_tot = rowmean(mech_nukechina mech_nukeindia mech_climatechina mech_climateindia)


	*-------------------------------------------------------------------------------
	* Manipulation Check
	*-------------------------------------------------------------------------------

	* Nukes
	gen nukes_check = .
	replace nukes_check = 1 if q59 == "Nuclear weapons"
	replace nukes_check = 0 if q59 == "Climate change" | q59 == "I don't recall"

	gen climate_check = .
	replace climate_check = 1 if q22 == "Climate change"
	replace climate_check = 0 if q22 == "Nuclear weapons" | q22 == "I don't recall"

	
	*-------------------------------------------------------------------------------
	* Duration
	*-------------------------------------------------------------------------------
	
	destring duration, replace
	gen duration_min = duration / 60

	*-------------------------------------------------------------------------------
	* Reshape
	*-------------------------------------------------------------------------------

	gen id = _n
	reshape long treat_ treat_topic_, i(id) j(qnum)
	keep if qnum == 1

	
	* Create Long-Version Treatment Variables
	*-------------------------------------------------------------------------------
	rename treat_topic_ treat_t 

	rename treat_ treat_long
	gen treat_pt = 1 if treat_long == 1 | treat_long == 2
	replace treat_pt = 0 if treat_long == 0

	lab def treat_pt 0 "Control" 1 "PT"
	lab val treat_pt treat_pt
	lab var treat_pt "Treatment [PT Dummy] Long Version"

	gen treat_c = .
	replace treat_c = 0 if treat_long == 0
	replace treat_c = 1 if treat_long == 1
	replace treat_c = 2 if treat_long == 2
	lab def treat_country 0 "Control" 1 "India" 2 "China"
	lab val treat_c treat_country

	* Create Mechanism Variables
	*-------------------------------------------------------------------------------
	tab mech_nukechina

	gen mech_coop = .
	replace mech_coop = mech_nukechina if treat_c == 2 & treat_t == 1
	replace mech_coop = mech_nukeindia if treat_c == 1 & treat_t == 1
	replace mech_coop = mech_climatechina if treat_c == 2 & treat_t == 0
	replace mech_coop = mech_climateindia if treat_c == 1 & treat_t == 0

	label val mech_coop mechanism

	* Generate Outcome Variables
	*-------------------------------------------------------------------------------

	* Generate DV
	* DV - Coop
	gen dv_coop = dv_climatecoop if treat_t == 0
	replace dv_coop = dv_nukecoop if treat_t == 1
	lab val dv_coop dv_coop 

	* DV Dummy - Coop
	gen dv_coop_dum = 1 if dv_coop == 4 | dv_coop == 5
	replace dv_coop_dum = 0 if dv_coop < 4

	* DV Unconditional
	gen dv_uncondition = dv_climateuncondition if treat_t == 0
	replace dv_uncondition = dv_nukeuncondition if treat_t == 1
	lab val dv_uncondition dv_uncondition

	* DV Condition
	gen dv_condition = dv_climatecondition if treat_t == 0
	replace dv_condition = dv_nukecondition if treat_t == 1
	lab val dv_condition dv_condition

	gen dv_onlyif = 1 if dv_climatecondition == 1 & treat_t == 0
	replace dv_onlyif = 1 if dv_nukecondition == 1 & treat_t == 1
	replace dv_onlyif = 0 if dv_climatecondition == 0 | dv_climatecondition == 2 & treat_t == 0
	replace dv_onlyif = 0 if dv_nukecondition == 0 | dv_nukecondition == 2 & treat_t == 0

	* DV Any
	gen dv_any = 1 if dv_condition == 1 | dv_condition == 2
	replace dv_any = 0 if dv_condition == 0

	gen dv_combined = (dv_uncondition + dv_coop_dum)/2

	* DV Qualitative
	gen dv_qual = ""
	replace dv_qual = dv_qual_clim if treat_t == 0
	replace dv_qual = dv_qual_nukes if treat_t == 1
	drop dv_qual_clim dv_qual_nukes

	*-------------------------------------------------------------------------------
	* Inverse Probability Weighting
	*-------------------------------------------------------------------------------

	* Wave 1: 1/3 to Control, 2/3 to PT
	gen ipw = .
	replace ipw = 1/(2/3) if treat_pt == 1 & wave == 1
	replace ipw = 1/(1/3) if treat_pt == 0 & wave == 1

	* Wave 2
	replace ipw = 1/(4/7) if treat_pt == 1 & wave == 2
	replace ipw = 1/(3/7) if treat_pt == 0 & wave == 2
	
	replace wave = 1 // Originally considered these two separate waves, but in final paper consider all mturk to be wave 1

	*-------------------------------------------------------------------------------
	* Manipulation Check
	*-------------------------------------------------------------------------------

	gen manip_check = .
	replace manip_check = 1 if nukes_check == 1 & treat_t == 1
	replace manip_check = 0 if nukes_check == 0 & treat_t == 1
	replace manip_check = 1 if climate_check == 1 & treat_t == 0
	replace manip_check = 0 if climate_check == 0 & treat_t == 0

	lab def check 1 "Correct" 0 "Wrong"
	lab val manip_check check
	lab var manip_check "Manipulation Check"

	* Save Data
	keep treat_pt treat_t treat_c dv_coop dv_coop_dum dv_condition c_age c_dem c_edu c_male c_pid c_pid_long c_white c_black c_latino mech_coop manip_check wave dv_qual u_id c_trust c_interventionist c_income ipw c_pt_* c_ce* c_ee* svy_duration dv_qual_omit
	save "${stata}\ptinir_data_wave1_clean.dta", replace


